﻿namespace FrameServer
{
    /// <summary>
    /// 单例模板
    /// </summary>
    /// <typeparam name="T"></typeparam>
    abstract class Singleton<T> where T : Singleton<T>, new()
    {
        private static T instance = null;
        private static readonly object _lock = new object();

        protected Singleton()
        {
        }

        public static T Instance
        {
            get
            {
                lock (_lock)
                {
                    if (instance == null)
                    {
                        instance = new T();
                        instance.AutoInit();
                    }
                    return instance;
                }
            }
        }

        protected virtual void AutoInit()
        {

        }

        public virtual void Dispose()
        {

        }
    }
}
